import java.util.Locale;

/**
 * @Author Stark
 * @Date 2022/2/15 10:58
 */
public class OperationOfString {
    public static void main(String[] args) {
        //1.字符串比较
//        String str1 = "hello";
//        System.out.println("Hello".equals(str1));
//        System.out.println("Hello".equalsIgnoreCase(str1));
//        System.out.println("Hello".compareTo(str1));
        //2.字符串查找
//        String str1 = "Hello world";
//        System.out.println(str1.contains("lle"));
//        System.out.println(str1.indexOf("llo"));
//        System.out.println(str1.indexOf("llo",2));
//        System.out.println(str1.lastIndexOf("llo"));
//        System.out.println(str1.lastIndexOf("llo",2));//???
//        System.out.println(str1.startsWith("He"));
//        System.out.println(str1.startsWith("wor",7));
//        System.out.println(str1.endsWith("ld"));
        //3.字符串替换
//        String str1 = "Hello world";
//        System.out.println(str1.replaceAll("o","e"));
//        System.out.println(str1.replaceFirst("e","o"));
        //4.字符串拆分
//        String str1 = "Hello world, ni hao";
//        String[] strings1 = str1.split(" ");
//        String[] strings2 = str1.split(" ",3);
//        for (String s :strings1
//                ) {
//            System.out.println(s);
//        }
//        for (String s :strings2
//        ) {
//            System.out.println(s);
//        }
//        String str = "192.168.1.1" ;
//        String[] result = str.split("\\.") ;
//        for(String s: result) {
//            System.out.println(s);
//        }
//        String str = "name=zhangsan&age=18" ;
//        String[] result = str.split("&") ;
//        for (int i = 0; i < result.length; i++) {
//            String[] temp = result[i].split("=") ;
//            System.out.println(temp[0]+" = "+temp[1]);
//        }
        //5.字符串截取
//        String str1 = "Hello world";
//        System.out.println(str1.substring(3));
//        System.out.println(str1.substring(3,7));
        //6.其他操作方法
        String str = "  hello  world  ";
        System.out.println(str.trim());
        System.out.println(str.toLowerCase());
        System.out.println(str.toUpperCase());
        System.out.println(str.concat(" hello"));
    }
}
